package com.softeem.swaggerdemo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * Configuration 表示当前类是一个被Spring管理的JavaBean
 * EnableSwagger2 启用Swagger
 *
 * @Author mrchai 2020/10/12 14:03
 */
@EnableSwagger2
@Configuration
public class SwaggerConfig {

    /**
     * softeem
     * @return
     */
//    @Bean
//    public Docket docket(){
//        return new Docket(DocumentationType.SWAGGER_2)
//                .groupName("softeem")
//                .apiInfo(apiInfo2())
//                .select()
//                .apis(RequestHandlerSelectors.basePackage("com.softeem.swaggerdemo.controller.system"))
//                .build();
//    }

    public ApiInfo apiInfo(){
        //创建联系人
        Contact contact = new Contact("德玛西亚","http://gitee.com/mrchai","630674409@qq.com");
        return new ApiInfo(
                "swgger测试文档",                           //文档标题
                "该文档为Swagger的基本使用介绍文档",    //文档描述
                "2.0",                                  //文档版本号
                "http://www.softeem.com",      //文档许可条款地址
                contact,
                "Apache 2.0",                            //开源许可
                "http://www.apache.org/licenses/LICENSE-2.0",   //开源许可地址
                new ArrayList()                                 //附加数据
        );
    }

    public ApiInfo apiInfo2(){
        return new ApiInfoBuilder()
                .title("人事管理系统API文档")
                .description("softeem-hrms系统，前端访问的使用文档")
                .version("1.0")
                .contact(new Contact("softeem","http://www.softeem.com","123@softeem.com"))
                .build();
    }

//    @Bean
//    public Docket docket2(){
//        return new Docket(DocumentationType.SWAGGER_2)
//                .groupName("jack")
//                .apiInfo(apiInfo2())
//                .select()
//                //限定对于哪些内容识别api
//                .apis(RequestHandlerSelectors.basePackage("com.softeem.swaggerdemo.controller.user"))
//                .build(); //配置swagger模板中的摘要信息
//    }

    @Bean
    public Docket docket3(Environment environment){
        //判断获取目前是否处于 dev 环境
        boolean dev = environment.acceptsProfiles(Profiles.of("dev"));

        return new Docket(DocumentationType.SWAGGER_2)
                //是否启用swagger
                .enable(dev)
                .groupName("rose")
                .apiInfo(apiInfo2())
                .select()
                //限定对于哪些内容识别api
                .apis(RequestHandlerSelectors.basePackage("com.softeem.swaggerdemo.controller.user"))
                .build(); //配置swagger模板中的摘要信息
    }

//    @Bean
//    public Docket docket4(){
//        return new Docket(DocumentationType.SWAGGER_2)
//                .groupName("韩梅梅")
//                .apiInfo(apiInfo2())
//                .select()
//                .apis(RequestHandlerSelectors.basePackage("com.softeem.swaggerdemo.controller.order"))
//                .build();
//    }

}
